//返回顶部
let returnTop = document.querySelector("#returnTop");
 console.log(returnTop);
// 窗口滚动事件
window.addEventListener("scroll", function () {
    // console.log(window.scrollY);
    // 控制返回顶部的显示和隐藏
    if (this.window.scrollY >= 500) {
        returnTop.style.display = "block"
    } else {
        returnTop.style.display = "none"

    }
})
returnTop.addEventListener("mouseenter", function () {
    this.style.backgroundPositionY = "-98px"
})
returnTop.addEventListener("mouseleave", function () {
    this.style.backgroundPositionY = "-56px"
})
let timerId = null;
returnTop.addEventListener("click", function () {
    let st = window.scrollY;//获取距离文档顶部的距离
    window.clearInterval(timerId);
    timerId = window.setInterval(function () {
        st -= 100;
        if (st <= 0) {
            st = 0;
            window.clearInterval(timerId)
        }
        window.scrollTo(0, st);

    }, 30)
})

